<template>
  <GBasicModal
    title="选择问卷"
    :destroyOnClose="true"
    width="500px"
    okText="确定"
    @ok="handleConfirm"
    @register="registerModal"
    :maskClosable="false"
  >
    <div class="pt-1">
      <a-select class="w-full" :options="options" v-model:value="selectedQuestionId" /> </div
  ></GBasicModal>
</template>

<script lang="ts" setup>
  import { useModalInner } from '@/components/Modal';

  const { createMessage } = useMessage();

  const emits = defineEmits(['ok', 'register']);

  const options = ref([
    {
      label: '2024-03-02',
      value: 11,
    },
    {
      label: '2024-03-01',
      value: 22,
    },
    {
      label: '2023-11-02',
      value: 33,
    },
  ]);

  const selectedQuestionId = ref('');

  const [registerModal, { closeModal }] = useModalInner(({ id }) => {
    //加载用户问卷
  });

  const handleConfirm = () => {
    if (!selectedQuestionId.value) {
      createMessage.error('请选择问卷');
      return;
    }
    emits('ok', selectedQuestionId.value);

    handleClose();
  };

  const handleClose = () => {
    options.value = [];
    selectedQuestionId.value = '';
    closeModal();
  };
</script>
